package cn.wolfcode.web.controller;

import cn.wolfcode.common.web.Result;
import cn.wolfcode.domain.OperateIntergralVo;
import cn.wolfcode.service.IUsableIntegralService;
import cn.wolfcode.service.impl.UsableIntegralServiceImpl;
import io.seata.rm.tcc.api.BusinessActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/integral")
public class IntegralController {
    private final IUsableIntegralService usableIntegralService;

    public IntegralController(IUsableIntegralService usableIntegralService) {
        this.usableIntegralService = usableIntegralService;
    }


    @PostMapping("/integralPay")
    public Result<String> integralPay(@RequestBody OperateIntergralVo vo) {
        String tradeNo = usableIntegralService.tryIntegralPay(null, vo);
        if (tradeNo != null) {
            return Result.success(tradeNo);
        }
        return Result.success("支付失败");
    }

    @PostMapping("/refund")
    public Result<Boolean> integralRefund(@RequestBody OperateIntergralVo vo) {
        usableIntegralService.integralRefund(vo);
        return Result.success(true);
    }
}
